﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using ClassLibrary.DAO;
using ClassLibrary.Entity;
using System.Data;

public partial class Admin_ucControl_ucTraGop : System.Web.UI.UserControl
{
    TblTraGopDAO tragopDAO = new TblTraGopDAO(Global.CONNECTION_STRING);

    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
            LoadTraGop();
            string id = Request.QueryString["id"];
            if (id != "" || id != null)
            {
                LoadDetail();
            }
        }
    }

    private void LoadDetail()
    {
        string id = Request.QueryString["id"];
        DataTable dt = tragopDAO.GetTraGop_ById(Global.ConvertToInt(id));
        foreach (DataRow dr in dt.Rows)
        {
            FCKTraGop.Value = dr["NoiDung"].ToString();
        }
    }

    private void LoadTraGop()
    {
        grdTraGop.DataSource = tragopDAO.GetTraGop();
        grdTraGop.DataBind();
    }
    protected void btnSave_Click(object sender, EventArgs e)
    {
        bool flag = false;
        try
        {
            TblTraGop tragop = new TblTraGop();
            tragop.NoiDung = FCKTraGop.Value;

            string id = Request.QueryString["id"];
            if (id == "" || id == null)
            {
               // tragopDAO.InsTraGop(tragop, 1);
            }
            else
            {
                tragop.ID = Global.ConvertToInt(id);
                tragopDAO.InsTraGop(tragop, 2);
            }

            flag = true;
        }
        catch (Exception ex)
        {
            throw ex;
        }
        if (flag)
        {
            Response.Redirect("~/Admin/TraGop.aspx");
        }
    }
}